home *** CD-ROM | disk | FTP | other *** search
/ Whiteline: Alpha / Whiteline Alpha.iso / linux / atari / source / source.lzh / atari-linux-0.01pl3 / m68k / head.S < prev    next >
Encoding:
Text File  |  1994-06-14  |  6.5 KB  |  353 lines

  1. /*
  2. ** head.S -- This file contains the initial boot code for the the
  3. **         ATARI Linux kernel.
  4. **
  5. ** Copyright 1994 by Björn Brauel
  6. **
  7. ** This file is subject to the terms and conditions of the GNU General Public
  8. ** License.  See the file README.legal in the main directory of this archive
  9. ** for more details.
  10. **
  11. */
  12.  
  13. #include "assyms.h"
  14.  
  15. /*
  16.  * Linux startup code.
  17.  *
  18.  * At this point, the boot loader has:
  19.  * Disabled interrupts
  20.  * Disabled caches
  21.  * Put us in supervisor state.
  22.  *
  23.  * The kernel setup code takes the following steps:
  24.  *   Raise interrupt level
  25.  *   Set up initial kernel memory mapping.
  26.  *    This sets up a mapping of the 4M of memory the kernel
  27.  *    is located in.    It also does a mapping of any initial
  28.  *    machine specific areas.
  29.  *   Enable cache memories
  30.  *   Jump to kernel startup
  31.  *
  32.  * Register d6 contains the CPU flags from the boot_info information
  33.  * for most of this file.
  34.  */
  35.  
  36. .text
  37. .globl _start, _krt, _kpt, _availmem
  38.  
  39.     .even
  40. _start:
  41. /*
  42.  * raise interrupt level with MASTER bit set, copy isp to msp
  43.  */
  44.     movew    #0x3700,sr
  45.     movec    isp,d0
  46.     movel    d0,sp
  47.  
  48. /*
  49.  * Initialize serial port
  50.  */
  51.     bsr Lserial_init
  52.  
  53.     moveq    #13,d7
  54.     bsr    Lserial_putc
  55.     moveq    #10,d7
  56.     bsr    Lserial_putc
  57.     moveq    #65,d7
  58.     bsr    Lserial_putc
  59.  
  60. /*
  61.  * Record the CPU type.
  62.  */
  63.     movel    #_boot_info,a0     /* pcrel */
  64.     subl    #LKSTART_ADDR,a0
  65.     addl    #LVSTART_STRAM,a0
  66.     movel    a0@(LBI_CPU),d6
  67.  
  68. /*
  69.  * Get address at end of kernel code/data/bss and
  70.  * mask off at a page boundary.
  71.  */
  72.     movel    #_end,a0  /* pcrel */
  73.     subl    #LKSTART_ADDR,a0
  74.     addl    #LVSTART_STRAM,a0
  75.     movel    a0,d0
  76.     addl    #0x00000fff,d0
  77.     andl    #0xfffff000,d0
  78.     movel    d0,a6
  79.  
  80.     moveq    #66,d7
  81.     bsr    Lserial_putc
  82.  
  83. /*
  84.  * allocate the kernel root table and initialize it.
  85.  */
  86.     movel    a6,a5
  87.     addw    #LPAGE_SIZE,a6
  88.  
  89.     /* clear the root table */
  90.     movel    a5,a0
  91.     moveq    #0,d0
  92.     moveq    #127,d1
  93. lopei:    movel    d0,a0@+
  94.     dbra    d1,lopei
  95.  
  96.     /*
  97.      * Initialize root table descriptor pointing to the kernel pointer
  98.      * table.  The pointer table is situated in memory right after
  99.      * the root table.
  100.      */
  101.     
  102.     /*
  103.      * Coming up specific Code for ATARI 
  104.      */
  105.      
  106.     lea    a5@,a0
  107.     movel    #0x0000001,d0
  108.     movel    #0x2000000,d1
  109.     movel        #127,d2
  110. f_rpt:    movel        d0,a0@+
  111.     addl    d1,d0
  112.     dbra     d2,f_rpt
  113.     
  114.     lea    a5@(1024),a0
  115.     addl    #2,a0
  116.     movel    a0,a5@(508) 
  117.  
  118.  
  119.     moveq    #67,d7
  120.     bsr    Lserial_putc
  121.  
  122. /*
  123.  * Initialize the pointer tables referred to above.  They either point
  124.  * to page tables in the case of the 68040 or contain early
  125.  * termination page descriptors in the case of the 68851 or 68030.
  126.  *
  127.  * Each pointer table entry points to a 64 entry page table.  16 of these
  128.  * page tables are grouped to form a single 1024 entry page table which
  129.  * fits in a single 4096 byte page.
  130.  *
  131.  * Some register usages:
  132.  *    a0 -> pointer table descriptor address
  133.  *    a1 -> pointer table descriptor
  134.  *    d1 -> counter
  135.  *    d2 -> pointer table descriptor increment (varies according to CPU)
  136.  */
  137.  
  138.     /* clear the kernel pointer table */
  139.     lea    a5@(512),a0
  140.     moveq    #0,d0
  141.     moveq    #127,d1
  142. lopzw:    movel    d0,a0@+
  143.     dbra    d1,lopzw
  144.  
  145.     lea    a5@(512),a0
  146.     moveq    #127,d1
  147.  
  148.     /*
  149.      * base value of pointer table descriptor is either
  150.      * the address of the first page table (68040)
  151.      * or the base address of physical memory (68030).
  152.      */
  153.  
  154.     /* 680[23]0 */
  155.     movel    #0,a1  /* base address */
  156.     addql    #1,a1        /* descriptor type */
  157.     movel    #0x40000,d2    /* increment */
  158.  
  159. lopb:    movel    a1,a0@+
  160.     addl    d2,a1
  161.     dbra    d1,lopb
  162.     addl    #0x40,a5@(0x2f0)
  163.     addl    #0x40,a5@(0x2f4)
  164.     addl    #0x40,a5@(0x2f8)
  165.     addl    #0x40,a5@(0x2fc)
  166.  
  167.     lea     a5@(1024),a0
  168.     movel    #0xfe000041,d0
  169.     movel    #0x40000,d1
  170.     movel        #63,d2
  171. f_kpt:    movel        d0,a0@+
  172.     addl    d1,d0
  173.     dbra     d2,f_kpt
  174.     movel    #63,d2
  175.     movel    #0x01,d0
  176. f_kpt2:    movel    d0,a0@+
  177.     addl    d1,d0
  178.     dbra     d2,f_kpt2
  179.     
  180.     lea    a5@(1536),a0
  181.     movel    #0x01,d0
  182.     movel    #127,d2
  183.     movel    #0x40000,d1
  184. f_vkpt:    movel    d0,a0@+
  185.     addl    d1,d0
  186.     dbra    d2,f_vkpt
  187.  
  188.     addl    #0x40,a5@(1532)
  189.     addl    #0x40,a5@(1520)
  190.     lea    a5@(1536),a0
  191.     addl    #2,a0
  192.     movel    a0,a5@(0x180)
  193.     
  194.     moveq    #74,d7
  195.     bsr    Lserial_putc
  196. /*
  197.  * Setup Supervisor Root Pointer register to point to page directory,
  198.  * setup translation register contents and enable translation.
  199.  */
  200.  
  201.     moveq    #75,d7
  202.     bsr    Lserial_putc
  203.  
  204.     movel    #Lmmu,a0  /* pcrel */
  205.     subl    #LKSTART_ADDR,a0
  206.     addl    #LVSTART_STRAM,a0
  207.     movel    #0x80000002,a0@   /* no limit, 4byte descriptors */
  208.     movel    a5,a0@(4)
  209.     pmove    a0@,srp
  210.  
  211.     /*
  212.      * enable,super root enable,4096 byte pages,7 bit root index,
  213.      * 7 bit pointer index, 6 bit page table index.
  214.      */
  215.     movel    #0x82c07760,a0@
  216.     pmove    a0@,tc
  217.  
  218.  
  219. /*
  220.  * Fixup the addresses for the kernel pointer table and availmem.
  221.  * Convert them from physical addresses to virtual addresses.
  222.  */
  223.     moveq    #77,d7
  224.     bsr    Lserial_putc
  225.  
  226.                              
  227.     lea    a5@(1536),a0
  228.     subl    #LVSTART_STRAM,a0
  229.     addl    #LKSTART_ADDR,a0
  230.     movel    a0,_kpt
  231.  
  232.  
  233.     /*
  234.      * do the same conversion on the first available memory
  235.      * address (in a6).
  236.      */
  237.     lea    a6@,a0
  238.     subl    #LVSTART_STRAM,a0
  239.     addl    #LKSTART_ADDR,a0
  240.     movel    a0,_availmem
  241.  
  242.     /* convert and save the root table address in memory */
  243.     lea    a5@,a0
  244.     subl    #LVSTART_STRAM,a0 
  245.     addl    #LKSTART_ADDR,a0
  246.     movel    a0,_krt
  247.  
  248.     /*
  249.      * Record starting address and jump into the virtual address space.
  250.      */
  251.     movel    #_start,a0   /* pcrel */
  252.     subl    #LKSTART_ADDR,a0
  253.     addl    #LVSTART_STRAM,a0
  254.  
  255.     jmp    Lvirt
  256.  
  257. Lvirt:
  258.     moveq    #78,d7
  259.     bsr    Lserial_putc
  260.  
  261.     /*
  262.      * Clean up the temporary physical mapping.
  263.      */
  264.  
  265.     pflusha         /* flush address translation cache */
  266.  
  267.  
  268.     moveq    #79,d7
  269.     bsr    Lserial_putc
  270.  
  271.  
  272. /*
  273.  * Enable caches
  274.  */
  275.  
  276.     movel    #0x00000919,d0
  277.     movec    d0,cacr
  278.  
  279.  
  280. /*
  281.  * Setup initial stack pointer
  282.  */
  283.     lea    _user_stack+LPAGE_SIZE,sp
  284.  
  285. /* jump to memory management initialization */
  286.  
  287.     moveq    #0,d0
  288.     movel    d0,sp@-     /* parameters to main */
  289.     movel    d0,sp@-
  290.     movel    d0,sp@-
  291.     bsr    _start_kernel
  292.  
  293.  
  294. /*
  295.  * Serial port output support.
  296.  */
  297.  
  298.  
  299. /*
  300.  * Initialize serial port hardware for 9600/8/1
  301.  */
  302. Lserial_init:
  303.     rts
  304.  
  305. /*
  306.  * Output character in d7 on serial port.
  307.  * d7 unchanged.
  308.  */
  309. Lserial_putc:
  310.     rts
  311.  
  312. /*
  313.  * Output string pointed to by a0 to serial port.
  314.  * a0 trashed.
  315.  */
  316. Lserial_puts:
  317.     rts
  318.  
  319. /*
  320.  * Output number in d7 in hex notation on serial port.
  321.  * d0-d2 trashed.
  322.  * d7 trashed.
  323.  */
  324. Lserial_putnum:
  325.     rts
  326.  
  327. /* Some nops to shift main.o backwards. This is necessary because the first
  328.  * 2 KByte of RAM are supervisor-only by hardware.
  329.  */
  330.     nop
  331.     nop
  332.     nop
  333.     nop
  334.     nop
  335.     nop
  336.     nop
  337.     nop
  338.     nop
  339.     nop
  340.     nop
  341.     nop
  342.     nop
  343.     nop
  344.     nop
  345.     nop
  346.  
  347.     .data
  348. Lmmu:    .long 0,0
  349. _krt:    .long 0
  350. _kpt:    .long 0
  351. _availmem:
  352.     .long 0
  353.